package com.twu.biblioteca.Options;

import com.twu.biblioteca.Account;
import com.twu.biblioteca.DataBase.User;

import java.util.Scanner;

public class LoginOption {
    private final Account account;
    private Scanner scanner;
    private String name;

    public String getName() {
        return name;
    }

    public LoginOption(Account account) {
        name = "Login";
        scanner = new Scanner(System.in);
        this.account = account;
    }

    public void execute(){
        System.out.println("Please type in Library Number to login");
        String  libraryNumber = scanner.nextLine();

        System.out.println("Please type in password");

        String password = scanner.nextLine();
        for(User user : account.getUsers()){
            if(user.getLibraryNumber().equals(libraryNumber) && user.getPassword().equals(password)){
                account.setCurrentUser(user);
                return;
            }
        }
        System.out.println("Library Number or Password is incorrect!");
    }
}
